import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import App from '../App.vue'
import Home from "../views/Home.vue";
const routes: Array<RouteRecordRaw> = [{
  path: '/',
  component: App, //顶层路由，对应index.html
  children: [ //二级路由。对应App.vue
    //地址为空时跳转home页面
    {
      path: '',
      redirect: '/home'
    },
    //首页城市列表页
    {
      path: '/home',
      component: Home
    },
    {
      path: '/city/:cityid',
      component:() =>
      import(/* webpackChunkName: "about" */ "../views/city.vue"),
      // () => require.ensure([], (require) => require(`../views/city.vue`))
      // component: () => require.ensure([], (require) => require(`../views/city.vue`))
    },
    {
      path: '/main',
      component:() =>
      import(/* webpackChunkName: "about" */ "../views/main.vue"),
      // () => require.ensure([], (require) => require(`../views/city.vue`))
      // component: () => require.ensure([], (require) => require(`../views/city.vue`))
    },
    {
      path: '/search/geohash',
      component:() =>
      import(/* webpackChunkName: "about" */ "../views/search.vue"),
      // () => require.ensure([], (require) => require(`../views/city.vue`))
      // component: () => require.ensure([], (require) => require(`../views/city.vue`))
    },
    {
      path: "/about",
      name: "About",
      // route level code-splitting
      // this generates a separate chunk (about.[hash].js) for this route
      // which is lazy-loaded when the route is visited.
      component: () =>
        import(/* webpackChunkName: "about" */ "../views/About.vue"),
    }]
}
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes,
});

export default router;
